package com.example.proyecto;

import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

@SuppressLint({ "NewApi", "NewApi", "NewApi" })
public class Proyecto extends Activity {

  
/** Called when the activity is first created. */

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.menu_principal);
    setContentView(R.layout.activity_proyecto);

  }

  public void startAnimation(View view) {
    float dest = 0;
    float posx, posy;   
    ImageView aniView = (ImageView) findViewById(R.id.imageView1);
    posx = aniView.getX();
    posy = aniView.getY();    
    String texto = posx +" "+ posy;
    TextView a = (TextView) findViewById(R.id.text1);
    ObjectAnimator animationx; 
    switch (view.getId()) {
    case R.id.Button01:      
    	posy = posy - 10;
    	if(posy<100){
    		dest = 360;
    		posy = 100;
    	      if (aniView.getRotation() == 360) {
    	        System.out.println(aniView.getAlpha());
    	        dest = 0;
    	      }
    	      animationx = ObjectAnimator.ofFloat(aniView,"rotation", dest);
    	      animationx.setDuration(2000);
    	      animationx.start();
    	}
    	texto = posx +" "+ posy;
    	a.setText(texto);
    	ObjectAnimator animation1 = ObjectAnimator.ofFloat(aniView,"y", posy);
    	animation1.setDuration(1500);
    	animation1.start();
      break;

    case R.id.Button02:
      posx = posx+10 ;
      if(posx>281){
  		dest = 360;
  		posx = 281;
  	      if (aniView.getRotation() == 360) {
  	        System.out.println(aniView.getAlpha());
  	        dest = 0;
  	      }
  	      animationx = ObjectAnimator.ofFloat(aniView,"rotation", dest);
  	      animationx.setDuration(2000);
  	      animationx.start();
  	}
      texto = posx +" "+ posy;      
      a.setText(texto);
      ObjectAnimator animation2 = ObjectAnimator.ofFloat(aniView,
          "x", posx);
      animation2.setDuration(1500);
      animation2.start();
      break;

    case R.id.Button03:
    	posx = posx-10 ;
    	if(posx<-10){
    		dest = 360;
    		posx = -10;
    	      if (aniView.getRotation() == 360) {
    	        System.out.println(aniView.getAlpha());
    	        dest = 0;
    	      }
    	      animationx = ObjectAnimator.ofFloat(aniView,"rotation", dest);
    	      animationx.setDuration(2000);
    	      animationx.start();
    	}    	
        texto = posx +" "+ posy;        
        a.setText(texto);
        ObjectAnimator animation3 = ObjectAnimator.ofFloat(aniView,"x", posx);
        animation3.setDuration(1500);
        animation3.start();
      break;

    case R.id.Button04:
      posy = posy + 10;
      if(posy>360){
  		dest = 360;
  		posy = 360;
  	      if (aniView.getRotation() == 360) {
  	        System.out.println(aniView.getAlpha());
  	        dest = 0;
  	      }
  	      animationx = ObjectAnimator.ofFloat(aniView,"rotation", dest);
  	      animationx.setDuration(2000);
  	      animationx.start();
  	}
  	texto = posx +" "+ posy;
  	a.setText(texto);
  	ObjectAnimator animation4 = ObjectAnimator.ofFloat(aniView,"y", posy);
  	animation4.setDuration(1500);
  	animation4.start();
      break;

    default:
      break;
    }

  }
/**
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    return super.onCreateOptionsMenu(menu);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent = new Intent(this, HitActivity.class);
    startActivity(intent);
    return true;
  }**/
} 
